﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TI_BAL;

namespace SecuritySystem
{
    public partial class UserListingForm : Form
    {
        TIEntities dbContext;
        

        public UserListingForm()
        {
            InitializeComponent();
            dbContext = new TIEntities();
        }

        private void RefreshGrid()
        {
            try
            {
             
                var listOfUsers = (from suser in dbContext.SecurityUsers
                                       select new { suser.UserId, suser.Name, suser.NIC, suser.FatherName, suser.MembershipId }).ToList();
                dataGridViewUser.DataSource = listOfUsers;

                dataGridViewUser.Columns[0].Visible = false;

                //dataGridViewSupplier.Columns["ID"].HeaderCell.Value = "ddd";
                dataGridViewUser.Columns["UserId"].HeaderCell.Value = "User ID";
                dataGridViewUser.Columns["Name"].HeaderCell.Value = "Person Name";
                dataGridViewUser.Columns["NIC"].HeaderCell.Value = "NIC";
                dataGridViewUser.Columns["FatherName"].HeaderCell.Value = "Father Name";
                dataGridViewUser.Columns["MembershipId"].HeaderCell.Value = "Member#";

            }
            catch (Exception e1)
            {


            }
        }

        private void UserListingForm_Load(object sender, EventArgs e)
        {
            RefreshGrid();
        }

        private void buttonAddSupplier_Click(object sender, EventArgs e)
        {
            AddEditUser form = new AddEditUser();


            form.MdiParent = this.MdiParent;

            form.Show();
            form.WindowState = FormWindowState.Minimized;
            form.WindowState = FormWindowState.Maximized;
        }

        private void buttonEditSelected_Click(object sender, EventArgs e)
        {
            AddEditUser form = new AddEditUser();

            //form.selectedRecord = dataGridViewUser.SelectedRows[0];
            form.MdiParent = this.MdiParent;

            form.Show();
            form.WindowState = FormWindowState.Minimized;
            form.WindowState = FormWindowState.Maximized;
        }
    }
}
